// vite.config.js
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

function resolve(dir) {
    return path.join(__dirname, dir)
}

export default defineConfig(({ mode }) => {
    console.log(mode)
    return {
        resolve: {
            alias: {
                '@': resolve('src')
            }
        },
        css: {
            preprocessorOptions: {
                less: {
                    modifyVars: {},
                    javascriptEnabled: true
                },
                scss: {
                    additionalData: `@import "src/styles/global.scss";`
                }
            }
        },
        plugins: [
            vue(),
            AutoImport({
                resolvers: [ElementPlusResolver()]
            }),
            Components({
                resolvers: [ElementPlusResolver()]
            })
        ],
        server: {
            port: 3000,
            host: '127.0.0.1',
            // ✅ 关键配置：解决 history 模式直接访问 404
            historyApiFallback: true
        },
        build: {
            commonjsOptions: {
                esmExternals: true,
                include: /node_modules|lib/
            }
        }
    }
})
